var ok ;
	
try{
		var connection = new SQLite("db.sqlite");
	ok=1;		
}catch(err){
	alert("Databa file missing. \n Please at the directory: C:/\Program Files/\Mozilla Thunderbird/\chrome give" +
		" full acces to your user name. ");
	ok = -1;
}
/**
	*@class initTable
	*@description This function will create the tables for to store the events
	*
	*@author Resz Janos
*/
function creatTables(){
	if (ok == -1)
		return;
	try{
	connection.execute("CREATE TABLE IF NOT EXISTS tb_category (categoryId INTEGER PRIMARY KEY AUTOINCREMENT, categoryName STRING )");
	connection.execute("CREATE TABLE IF NOT EXISTS tb_reminder (reminderId INTEGER PRIMARY KEY AUTOINCREMENT, remind INTEGER,reminderName STRING )");	
	connection.execute("CREATE TABLE IF NOT EXISTS tb_repeat (repeatId INTEGER PRIMARY KEY AUTOINCREMENT, repeatName STRING )"); 						
	connection.execute("CREATE TABLE IF NOT EXISTS tb_event (eventId INTEGER PRIMARY KEY AUTOINCREMENT,"+
						"categoryId INTEGER REFERENCES tb_category (categoryId), reminderId INTEGER REFERENCES tb_reminder (reminderId),"+
						"repeatId INTEGER REFERENCES tb_repeat (repeatId),"+
						"hour INTEGER,minute INTEGER, name STRING, location STRING, description STRING,year INTEGER, month INTEGER, day INTEGER,"+
						"endYear INTEGER, endMonth INTEGER, endDay INTEGER, endHour INTEGER, endMinute INTEGER,"+
						"remindYear INTEGER, remindMonth INTEGER, remindDay INTEGER,"+
						"remindHour INTEGER, remindMinute INTEGER)");
	}catch(err){
			alert("Not create tables"+ err);
		return;
	}	
		
}
/**
	*@class initTable
	*@description This function will delete the tables
	*
	*@author Resz Janos
*/
function deleteTables(){

	if (ok == -1)
		return;

	try{
		connection.execute("DROP TABLE IF EXISTS tb_reminder");
		connection.execute("DROP TABLE IF EXISTS tb_repeat");
		connection.execute("DROP TABLE IF EXISTS tb_category");
		connection.execute("DROP TABLE IF EXISTS tb_event");
	}catch(err){
		alert("Not delete tables" +err);
		return;
	}
}

/**
	*@class initTable
	*@description This function will init the tables.
	*
	*@author Resz Janos
*/
function initTables(){
	
	if (ok == -1)
		return;
	try{
		connection.execute("INSERT INTO tb_reminder (remind,reminderName) VALUES (15,"+
							"'15 minutes before')");
		connection.execute("INSERT INTO tb_reminder (remind,reminderName) VALUES (30,"+
							"'30 minutes before')");
		connection.execute("INSERT INTO tb_reminder (remind,reminderName) VALUES (60,"+
						   "'One hour before')");
		connection.execute("INSERT INTO tb_reminder (remind,reminderName) VALUES (1440,"+
						   "'Before a day')");
		connection.execute("INSERT INTO tb_reminder (remind,reminderName) VALUES (0,"+
						   "'Events given time')");
		connection.execute("INSERT INTO tb_repeat (repeatName) VALUES ("+
							"'Daily')");
		connection.execute("INSERT INTO tb_repeat (repeatName) VALUES ("+
							"'Weekly')");
		connection.execute("INSERT INTO tb_repeat (repeatName) VALUES ("+
						   "'Monthly')");
		connection.execute("INSERT INTO tb_repeat (repeatName) VALUES ("+
						   "'Yearly')");
		connection.execute("INSERT INTO tb_repeat (repeatName) VALUES ("+
						   "'No repeat')");
		connection.execute("INSERT INTO tb_category (categoryName) VALUES ('Birthday')");
		connection.execute("INSERT INTO tb_category (categoryName) VALUES ('Name day')");
		connection.execute("INSERT INTO tb_category (categoryName) VALUES ('Anniversary')");
		connection.execute("INSERT INTO tb_category (categoryName) VALUES ('Other')");		
	
	}catch(err){
		alert("Not init tables" +err);
		return;
	}
}

